import axios from "axios";
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
// axios实例
//开发环境地址http://127.0.0.1:8081
console.log(process.env.REACT_APP_API_URL);

const request = axios.create({
    baseURL: process.env.REACT_APP_API_URL,
    timeout: 10000,
    headers: {
        "Content-Type": "application/json;charset=UTF-8"
    }
})


//请求拦截器
request.interceptors.request.use((config) => {
    const token = localStorage.getItem('web_token')
    if (token) {
        config.headers.Authorization = `Bearer ${token}`
    }
    NProgress.start();
    return config
}, error => {
    return Promise.reject(error)
})

//响应拦截器
request.interceptors.response.use((response) => {
    NProgress.done()
    return response.data
}, error => {
    // if (error.response.status === 401) {
    //     message.error("获取数据出现异常!")
    // }
    return Promise.reject(error)
})

export default request;

